/**
 * 每次部署的时候，都不要忘记修改这个路径
 */
require.config({
    paths: {
    	echarts: GLOBAL.WEBAPP+'/echarts/build/dist'
	}
});

/**
 * 这是一个判空的函数，可以单独提出来放到工具类中
 * 
 * @param str
 * @returns {Boolean}
 */
function IsEmptyData(str) {
	var result = false;
	if (str == null || typeof (str) == 'undefined') {
		result = true;
	} else {
		var reg = new RegExp(" ", "g");
		str += "";
		str = str.replace(reg, "");
		if (str.length == 0) {
			result = true;
		}
	}

	return result;
}


/**
 * 饼图构建辅助方法
 * 
 * @param divid
 *            容器ID
 * @param ajaxdata
 *            JSON数据
 * @param piesetting
 *            包含属性：name, value, titletext, subtitletext, seriesname, islegend,
 *            legendalign, istoolbox, titlealign, orienttype
 * @param name
 *            名称 列名
 * @param value
 *            值 列名
 * @param titletext
 *            主标题
 * @param subtitletext
 *            副标题
 * @param seriesname
 *            提示框名称
 * @param islegend
 *            是否显示示例，默认值true
 * @param legendalign
 *            图例显示位置，默认值left
 * @param istoolbox
 *            是否显示右上方的工具栏，默认值true
 * @param istooltip
 *            是否显示提示框，默认值true
 * @param titlealign
 *            标题位置，默认值center
 * @param orienttype
 *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
 * @param chartradius
 *            饼图半径,默认55%，传入数组实现环形图[内半径，外半径]
 * @param itemStyle
 *            设置提示文字样式
 * @param color
 *            设置颜色带，需传入一个组个数量的数组
 * @param titleStyle
 *            标题样式
 */
function InitECharts_pie(divid, ajaxdata, piesetting) {
	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
		alert("绑定的容器ID不存在");
		return false;
	}

	if (IsEmptyData(ajaxdata)) {
		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
			document.getElementById(divid).removeChild(
					document.getElementById(divid).childNodes[i]);
		}
		return false;
	}

	if (IsEmptyData(piesetting)) {
		alert("设置为空或不正确");
		return false;
	}

	if (IsEmptyData(piesetting.titletext)) {
		piesetting.titletext = "";
	}
	if (IsEmptyData(piesetting.subtitletext)) {
		piesetting.subtitletext = "";
	}

	if (IsEmptyData(piesetting.seriesname)) {
		piesetting.seriesname = "";
	}

	if (IsEmptyData(piesetting.islegend)) {
		piesetting.islegend = true;
	}

	if (IsEmptyData(piesetting.xlegendalign)) {
		piesetting.xlegendalign = 'left';
	}
	if (IsEmptyData(piesetting.ylegendalign)) {
		piesetting.ylegendalign = 'bottom';
	}
	

	if (IsEmptyData(piesetting.istoolbox)) {
		piesetting.istoolbox = true;
	}

	if (IsEmptyData(piesetting.istooltip)) {
		piesetting.istooltip = true;
	}

	if (IsEmptyData(piesetting.titlealign)) {
		piesetting.titlealign = "center";
	}

	if (IsEmptyData(piesetting.orienttype)) {
		piesetting.orienttype = "horizontal";
	}

	if (IsEmptyData(piesetting.chartradius)) {
		piesetting.chartradius = "45%";
	}
	if (IsEmptyData(piesetting.titleStyle)) {
		piesetting.titleStyle = {};
	}
	if (IsEmptyData(piesetting.name)) {
		piesetting.name = 'name';
	}
	if (IsEmptyData(piesetting.value)) {
		piesetting.value = 'value';
	}
	if (IsEmptyData(piesetting.theme)) {
		piesetting.theme = 'macarons';
	}

	var itemStyle = {
			normal : {
                color: function(params) {
                    // macarons 颜色代码
                    var colorList = [
                                     '#2ec7c9','#b6a2de','#5ab1ef','#ffb980','#d87a80',
                                     '#8d98b3','#e5cf0d','#97b552','#95706d','#dc69aa',
                                     '#07a2a4','#9a7fd1','#588dd5','#f5994e','#c05050',
                                     '#59678c','#c9ab00','#7eb00a','#6f5553','#c14089'
                                    
                    ];
                    return colorList[params.dataIndex]
                },
                label : {
                    	position : 'outer',
                    	formatter: "{d}%",
            	        textStyle:{
            	        	fontFamily: 'Microsoft YaHei,微软雅黑,宋体',
            	        	fontWeight:'normal',
            	        }
                    },
                labelLine : {
                    show : true
                }
            }
	};
	var legend = "";

	if (piesetting.islegend) {
		var data = [];

		for ( var i = 0; i < ajaxdata.length; i++) {
			data.push(ajaxdata[i][piesetting.name]);
		}

		legend = {
			orient : piesetting.orienttype,
			x : piesetting.xlegendalign,
			y : piesetting.ylegendalign,
			textStyle:{
   	        	fontFamily: 'Microsoft YaHei,微软雅黑'
   	        },
			data : data
		};
	}

	var piedata = [];

	for ( var i = 0; i < ajaxdata.length; i++) {
		piedata.push({
			value : ajaxdata[i][piesetting.value],
			name : ajaxdata[i][piesetting.name]
		});
	}
	var option = {
		title : {
			text : piesetting.titletext,
			subtext : piesetting.subtitletext,
			x : piesetting.titlealign,
			textStyle : piesetting.titleStyle
		},
		tooltip : {
			show : piesetting.istooltip,
			trigger : 'item',
			formatter : (piesetting.seriesname ? "{a} <br/>{b}:{d}%"
					: "{b}:{d}%"),
			position : function(posit) {
				return [ posit[0] - 10, posit[1] + 30 ];// 位置指定
			}
		},
		legend : legend,
		toolbox : {
			show : piesetting.istoolbox,
			feature : {
				mark : {
					show : false
				},
				dataView : {
					show : true,
					readOnly : false
				},
				magicType : {
					show : false,
					type : [ 'pie', 'funnel' ],
					option : {
						funnel : {
							x : '25%',
							width : '50%',
							funnelAlign : 'left',
							max : 1548
						}
					}
				},
				restore : {
					show : true
				},
				saveAsImage : {
					show : true
				}
			}
		},
		calculable : false,
		// clickable : true,
		series : [ {
			name : piesetting.seriesname,
			type : 'pie',
			radius : piesetting.chartradius,
			center : [ '50%', '40%' ],
			itemStyle:itemStyle,
			data : piedata
		} ]
	};

	if (!IsEmptyData(piesetting.itemStyle)) {
		option.series[0].itemStyle = piesetting.itemStyle;
	}

	if (!IsEmptyData(piesetting.color)) {
		option.color = piesetting.color;
	}
	
	var myChart1 = null;
	require([ 'echarts', 'echarts/chart/pie', 'echarts/chart/funnel' ],
			function(ec) {
				var ecConfig = require('echarts/config');
				myChart1 = ec.init(document.getElementById(divid),piesetting.theme);
				window.onresize = myChart1.resize;
				myChart1.clear();
				myChart1.setOption(option);
				
				//点击事件
				if(!IsEmptyData(piesetting.clickFunc)){
					 //为echarts添加点击事件
			        myChart1.on(ecConfig.EVENT.CLICK,function(param){
			        	//判断是否需要从外界传点击参数
			        	if(IsEmptyData(piesetting.clickParams)){
			        		//没有额外的参数直接传echart参数
			        		piesetting.clickFunc(param);
			        	}else{
			        		//setting里面有额外的参数，传两个
			        		piesetting.clickFunc(param,piesetting.clickParams);
			        	}
			        	
			        })
				}
				
			});
	
	return myChart1;
}

/**
 * 环形图构建辅助方法
 * 
 * @param divid
 *            容器ID
 * @param ajaxdata
 *            JSON数据
 * @param piesetting
 *            包含属性：name, value, titletext, subtitletext, seriesname, islegend,
 *            legendalign, istoolbox, titlealign, orienttype
 * @param name
 *            名称 列名
 * @param value
 *            值 列名
 * @param titletext
 *            主标题
 * @param subtitletext
 *            副标题
 * @param seriesname
 *            提示框名称
 * @param islegend
 *            是否显示示例，默认值true
 * @param legendalign
 *            图例显示位置，默认值left
 * @param istoolbox
 *            是否显示右上方的工具栏，默认值true
 * @param istooltip
 *            是否显示提示框，默认值true
 * @param titlealign
 *            标题位置，默认值center
 * @param orienttype
 *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
 * @param chartradius
 *            饼图半径,默认55%，传入数组实现环形图[内半径，外半径]
 * @param itemStyle
 *            设置提示文字样式
 * @param color
 *            设置颜色带，需传入一个组个数量的数组
 * @param titleStyle
 *            标题样式
 */
function InitECharts_ring(divid, ajaxdata, piesetting) {
	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
		alert("绑定的容器ID不存在");
		return false;
	}

	if (IsEmptyData(ajaxdata)) {
		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
			document.getElementById(divid).removeChild(
					document.getElementById(divid).childNodes[i]);
		}
		return false;
	}

	if (IsEmptyData(piesetting)) {
		alert("设置为空或不正确");
		return false;
	}

	if (IsEmptyData(piesetting.titletext)) {
		piesetting.titletext = "";
	}
	if (IsEmptyData(piesetting.subtitletext)) {
		piesetting.subtitletext = "";
	}

	if (IsEmptyData(piesetting.seriesname)) {
		piesetting.seriesname = "";
	}

	if (IsEmptyData(piesetting.islegend)) {
		piesetting.islegend = true;
	}

	if (IsEmptyData(piesetting.xlegendalign)) {
		piesetting.xlegendalign = 'left';
	}
	if (IsEmptyData(piesetting.ylegendalign)) {
		piesetting.ylegendalign = 'bottom';
	}
	

	if (IsEmptyData(piesetting.istoolbox)) {
		piesetting.istoolbox = true;
	}

	if (IsEmptyData(piesetting.istooltip)) {
		piesetting.istooltip = true;
	}

	if (IsEmptyData(piesetting.titlealign)) {
		piesetting.titlealign = "center";
	}
	 //图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
	if (IsEmptyData(piesetting.orienttype)) {
		piesetting.orienttype = "horizontal";
	}

	if (IsEmptyData(piesetting.chartradius)) {
		piesetting.chartradius = ['35%', '55%'];
	}
	if (IsEmptyData(piesetting.titleStyle)) {
		piesetting.titleStyle = {};
	}
	
	if (IsEmptyData(piesetting.name)) {
		piesetting.name = 'name';
	}
	if (IsEmptyData(piesetting.value)) {
		piesetting.value = 'value';
	}
	if (IsEmptyData(piesetting.theme)) {
		piesetting.theme = 'macarons';
	}
	if (IsEmptyData(piesetting.labelformatter)) {
		piesetting.labelformatter = '{b}\n{c}%';
	}

	//默认的itemStyle
	var itemStyle = {
         normal : {
        	label:{
        		position : 'outer',
               	formatter: "{d}%",
        	        textStyle:{
     	        	fontFamily: 'Microsoft YaHei,微软雅黑,宋体',
     	        	fontWeight:'normal'
     	        },
        	},
             labelLine : {
                 show : true
             }
         },
         emphasis : {
             label : {
                 show : false,
                 position : 'center',
                 textStyle : {
                     fontSize : '30',
                     fontWeight : 'bold'
                 }
             }
         }
     };
    
	var legend = "";

	if (piesetting.islegend) {
		var data = [];

		for ( var i = 0; i < ajaxdata.length; i++) {
			data.push(ajaxdata[i][piesetting.name]);
		}

		legend = {
			orient : piesetting.orienttype,
			x : piesetting.xlegendalign,
			y : piesetting.ylegendalign,
			textStyle:{
   	        	fontFamily: 'Microsoft YaHei,微软雅黑'
   	        },
			data : data
		};
	}

	var piedata = [];

	for ( var i = 0; i < ajaxdata.length; i++) {
		piedata.push({
			value : ajaxdata[i][piesetting.value],
			name : ajaxdata[i][piesetting.name]
		});
	}
	var option = {
		title : {
			text : piesetting.titletext,
			subtext : piesetting.subtitletext,
			x : piesetting.titlealign,
			textStyle : piesetting.titleStyle
		},
		tooltip : {
			show : piesetting.istooltip,
			trigger : 'item',
			formatter : (piesetting.seriesname ? "{a} <br/>{b}:{d}%"
					: "{b}:{d}%"),
			position : function(posit) {
				return [ posit[0] - 10, posit[1] + 30 ];// 位置指定
			}
		},
		legend : legend,
		toolbox : {
			show : piesetting.istoolbox,
			feature : {
				mark : {
					show : false
				},
				dataView : {
					show : true,
					readOnly : false
				},
				magicType : {
					show : false,
					type : [ 'pie', 'funnel' ],
					option : {
						funnel : {
							x : '25%',
							width : '50%',
							funnelAlign : 'left',
							max : 1548
						}
					}
				},
				restore : {
					show : true
				},
				saveAsImage : {
					show : true
				}
			}
		},
		calculable : false,
		// clickable : true,
		series : [ {
			name : piesetting.seriesname,
			type : 'pie',
			radius : piesetting.chartradius,
			itemStyle:itemStyle,
			data : piedata
		} ]
	};

	if (!IsEmptyData(piesetting.itemStyle)) {
		option.series[0].itemStyle = piesetting.itemStyle;
	}

	if (!IsEmptyData(piesetting.color)) {
		option.color = piesetting.color;
	}
	
	var myChart1 = null;
	require([ 'echarts', 'echarts/chart/pie', 'echarts/chart/funnel' ],
			function(ec) {
				var ecConfig = require('echarts/config');
				myChart1 = ec.init(document.getElementById(divid),piesetting.theme);
				myChart1.clear();
				myChart1.setOption(option);
				window.onresize = myChart1.resize;
				//点击事件
				if(!IsEmptyData(piesetting.clickFunc)){
					 //为echarts添加点击事件
			      
					myChart1.on(ecConfig.EVENT.CLICK,function(param){
			        	//判断是否需要从外界传点击参数
			        	if(IsEmptyData(piesetting.clickParams)){
			        		//没有额外的参数直接传echart参数
			        		piesetting.clickFunc(param);
			        	}else{
			        		//setting里面有额外的参数，传两个
			        		piesetting.clickFunc(param,piesetting.clickParams);
			        	}
			        	
			        })
				}
				
			});
	
	
	return myChart1;
}

/**
 * 柱线混合图构建辅助方法
 * 
 * @param divid
 *            容器ID
 * @param ajaxdata
 *            JSON数据
 * @param barsetting
 *            包含:name, valuearry, textarry, typearry, yAxisarry, titletext,
 *            subtitletext, islegend, legendalign, istoolbox, titlealign,
 *            orienttype
 * @param name
 *            名称 列名
 * @param valuearry
 *            值 列名数组
 * @param textarry
 *            图例 名称数组
 * @param typearry
 *            显示类型 数组 柱bar 线line
 * @param stackarry
 *            群组属性（相同群组名称的多柱显示为层叠效果）
 * @param yAxisarry
 *            y轴显示名称和单位集合 例:[{ name : '数量', text : '个' }, { name : '概率', text :
 *            '%' } ];
 * @param titletext
 *            主标题
 * @param subtitletext
 *            副标题
 * @param islegend
 *            是否显示图例，默认值true
 * @param legendalign
 *            图例显示位置，默认值left
 * @param istoolbox
 *            是否显示右上方的工具栏，默认值true
 * @param istooltip
 *            是否显示提示框，默认值true
 * @param titlealign
 *            标题位置，默认值center
 * @param orienttype
 *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
 * @param islongtext
 *            长文本处理方式，倾斜45°，12px
 * @param chartwidth
 *            统计图主体的宽度，默认70%
 * @param chartheight
 *            统计图主体的高度，默认70%
 * @param isdataZoom
 *            是否显示时间轴
 * @param zoomstart
 *            时间轴区间开始百分比（区间在0-100）
 * @param zoomend
 *            时间轴区间结束百分比（区间在0-100）
 * @param isrealtime
 *            缩放变化是否实时显示，默认true
 * @param zoomheight
 *            时间轴区域的高度
 * @param x
 *            主体的x坐标
 * @param y
 *            主体的y坐标
 */
 function InitECharts_bar(divid, ajaxdata, barsetting) {
	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
		alert("绑定的容器ID不存在");
		return false;
	}

	if (IsEmptyData(ajaxdata)) {
		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
			document.getElementById(divid).removeChild(
					document.getElementById(divid).childNodes[i]);
		}
	}

	if (IsEmptyData(barsetting)) {
		alert("设置为空或不正确");
		return false;
	}

	if (IsEmptyData(barsetting.islegend)) {
		//柱形图不显示图例
		barsetting.islegend = false;
	}

	if (IsEmptyData(barsetting.legendalign)) {
		barsetting.legendalign = 'left';
	}

	if (IsEmptyData(barsetting.istoolbox)) {
		barsetting.istoolbox = true;
	}

	if (IsEmptyData(barsetting.istooltip)) {
		barsetting.istooltip = true;
	}

	if (IsEmptyData(barsetting.titlealign)) {
		barsetting.titlealign = "center";
	}
	if (IsEmptyData(barsetting.orienttype)) {
		barsetting.orienttype = "vertical";
	}


	if (IsEmptyData(barsetting.islongtext)) {
		barsetting.islongtext = false;
	}
	
	if (IsEmptyData(barsetting.grid)) {
		barsetting.grid={borderWidth: 0,y:'10%',y2:'10%',x:'10%',x2:'10%'};
	}
	if (IsEmptyData(barsetting.name)) {
		barsetting.name = 'name';
	}
	if (IsEmptyData(barsetting.value)) {
		barsetting.value = 'value';
	}
	if (IsEmptyData(barsetting.theme)) {
		barsetting.theme = 'macarons';
	}
	
	if (IsEmptyData(barsetting.labelformatter)) {
		barsetting.labelformatter = '{b}\n{c}';
	}
	
	if (IsEmptyData(barsetting.labelposition)) {
		barsetting.labelposition = 'top';
	}
	if (IsEmptyData(barsetting.tipformatter)) {
		barsetting.tipformatter = '{b}:{c}';
	}
	if (IsEmptyData(barsetting.yLabelfromatter)) {
 		barsetting.yLabelfromatter = '{value}';
 	}
	if (IsEmptyData(barsetting.xLabelfromatter)) {
 		barsetting.xLabelfromatter = '{value}';
 	}
	//设置条图竖着还是横着
	if (IsEmptyData(barsetting.overturn)) {
		barsetting.overturn = false;
	}
	if (IsEmptyData(barsetting.xLabelName)) {
 		barsetting.xLabelName = '';
 	}


	var legend = "";
	if (barsetting.islegend) {
		var data = [];

		for ( var i = 0; i < ajaxdata.length; i++) {
			data.push(ajaxdata[i][barsetting.name]);
		}
		legend = {
			orient : barsetting.orienttype,
			x : barsetting.legendalign,
			data : data
		};
	}

	var labelstyle = {
		rotate : 0,
	    formatter:barsetting.xLabelfromatter
	};
	
	if (barsetting.islongtext) {
		labelstyle = {
			rotate : 45,
			textStyle : {
				align : 'left',
				baseline : 'middle',
				fontSize : 12
			},
			axisLabel:{
		    	formatter:barsetting.xLabelfromatter
		    }
		};
	}
	//x轴和y轴数据
	var xdata = [];
	var ydata = [];
	
	var xtype = 'category';
	var ytype = 'value';
	if(barsetting.overturn){
		//横纵坐标轴反向
		xtype = 'value';
		ytype = 'category';
		//将labe右侧显示
		barsetting.labelposition = 'right';
	}
	
	for ( var i = 0; i < ajaxdata.length; i++) {
		//x轴数据
		xdata.push(ajaxdata[i][barsetting.name]);
		//y轴数据
		ydata.push(ajaxdata[i][barsetting.value]);
		
	}
	var bardata = [{
		"type":"bar",
        "data":ydata,
         barMaxWidth :40,
         itemStyle: {
             normal: {
                 color: function(params) {
                	// macarons 颜色代码
                     var colorList = [
                                      '#2ec7c9','#b6a2de','#5ab1ef','#ffb980','#d87a80',
                                      '#8d98b3','#e5cf0d','#97b552','#95706d','#dc69aa',
                                      '#07a2a4','#9a7fd1','#588dd5','#f5994e','#c05050',
                                      '#59678c','#c9ab00','#7eb00a','#6f5553','#c14089'
                                     
                     ];
                     return colorList[params.dataIndex]
                 },
                 label: {
                    show: true,
                    position: barsetting.labelposition,
                    formatter: barsetting.labelformatter,
         	        textStyle:{
	      	        	fontFamily: 'Microsoft YaHei,微软雅黑,宋体',
	      	        	fontWeight:'normal',
	      	        	fontSize:10
         	        }
                 },
                
                 barBorderRadius:[5,5,5,5],
                 
             }
         }
	}]
	
	var option = {
		title : {
			text : barsetting.titletext,
			subtext : barsetting.subtitletext,
			x : barsetting.titlealign
		},
		tooltip : {
			show : barsetting.istooltip,
			trigger : 'item',
			formatter : barsetting.tipformatter,
		},
		
		toolbox : {
			show : barsetting.istoolbox,
			feature : {
				mark : {
					show : false
				},
				dataView : {
					show : true,
					readOnly : false
				},
				magicType : {
					show : false,
					type : [ 'bar', 'line', 'stack', 'tiled' ]
				},
				restore : {
					show : true
				},
				saveAsImage : {
					show : true
				}
			}
		},
		calculable : false,
		legend : legend,
		xAxis : [{
			// width: '50%',
			type : xtype,
			data : xdata,
			name:barsetting.xLabelName,
			show:true,
			axisLabel : labelstyle
		}],
		yAxis : [{
				    type: ytype,
				    data: xdata,
				    show:true,
				    axisLabel:{
				    	formatter:barsetting.yLabelfromatter
				    }
				}],
		grid : barsetting.grid,
		series : bardata
	};

	if (barsetting.x) {
		option.grid.x = barsetting.x;
	}

	if (barsetting.y) {
		option.grid.y = barsetting.y;
	}

	var myChart1 = null;
	require([ 'echarts', 'echarts/chart/bar', 'echarts/chart/line' ], function(
			ec) {
		var ecConfig = require('echarts/config');
		myChart1 = ec.init(document.getElementById(divid),barsetting.theme);
		myChart1.clear();
		window.onresize = myChart1.resize;
		myChart1.setOption(option);
		
		//点击事件
		if(!IsEmptyData(barsetting.clickFunc)){
			 //为echarts添加点击事件
	    
			myChart1.on(ecConfig.EVENT.CLICK,function(param){
				
	        	//判断是否需要从外界传点击参数
	        	if(IsEmptyData(barsetting.clickParams)){
	        		//没有额外的参数直接传echart参数
	        		barsetting.clickFunc(param);
	        	}else{
	        		//setting里面有额外的参数，传两个
	        		barsetting.clickFunc(param,barsetting.clickParams);
	        	}
	        	
	        })
		}
		
	});
	
	// var ecConfig = require('echarts/config');
	return myChart1;
}
 
 /**
  * 柱线混合图构建辅助方法
  * 
  * @param divid
  *            容器ID
  * @param ajaxdata
  *            JSON数据
  * @param barsetting
  *            包含:name, valuearry, textarry, typearry, yAxisarry, titletext,
  *            subtitletext, islegend, legendalign, istoolbox, titlealign,
  *            orienttype
  * @param name
  *            名称 列名
  * @param valuearry
  *            值 列名数组
  * @param textarry
  *            图例 名称数组
  * @param typearry
  *            显示类型 数组 柱bar 线line
  * @param stackarry
  *            群组属性（相同群组名称的多柱显示为层叠效果）
  * @param yAxisarry
  *            y轴显示名称和单位集合 例:[{ name : '数量', text : '个' }, { name : '概率', text :
  *            '%' } ];
  * @param titletext
  *            主标题
  * @param subtitletext
  *            副标题
  * @param islegend
  *            是否显示图例，默认值true
  * @param legendalign
  *            图例显示位置，默认值left
  * @param istoolbox
  *            是否显示右上方的工具栏，默认值true
  * @param istooltip
  *            是否显示提示框，默认值true
  * @param titlealign
  *            标题位置，默认值center
  * @param orienttype
  *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
  * @param islongtext
  *            长文本处理方式，倾斜45°，12px
  * @param chartwidth
  *            统计图主体的宽度，默认70%
  * @param chartheight
  *            统计图主体的高度，默认70%
  * @param isdataZoom
  *            是否显示时间轴
  * @param zoomstart
  *            时间轴区间开始百分比（区间在0-100）
  * @param zoomend
  *            时间轴区间结束百分比（区间在0-100）
  * @param isrealtime
  *            缩放变化是否实时显示，默认true
  * @param zoomheight
  *            时间轴区域的高度
  * @param x
  *            主体的x坐标
  * @param y
  *            主体的y坐标
  */
  function InitECharts_multibar(divid, ajaxdata, barsetting) {
 	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
 		alert("绑定的容器ID不存在");
 		return false;
 	}

 	if (IsEmptyData(ajaxdata)) {
 		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
 			document.getElementById(divid).removeChild(
 					document.getElementById(divid).childNodes[i]);
 		}
 	}

 	if (IsEmptyData(barsetting)) {
 		alert("设置为空或不正确");
 		return false;
 	}

 	if (IsEmptyData(barsetting.islegend)) {
 		//柱形图不显示图例
 		barsetting.islegend = true;
 	}

 	if (IsEmptyData(barsetting.legendxalign)) {
 		barsetting.legendxalign = 'left';
 	}
 	if (IsEmptyData(barsetting.legendyalign)) {
 		barsetting.legendyalign = 'bottom';
 	}

 	if (IsEmptyData(barsetting.istoolbox)) {
 		barsetting.istoolbox = true;
 	}

 	if (IsEmptyData(barsetting.istooltip)) {
 		barsetting.istooltip = true;
 	}

 	if (IsEmptyData(barsetting.titlealign)) {
 		barsetting.titlealign = "center";
 	}
 	if (IsEmptyData(barsetting.orienttype)) {
 		barsetting.orienttype = "horizontal";
 	}


 	if (IsEmptyData(barsetting.islongtext)) {
 		barsetting.islongtext = false;
 	}
 	
 	if (IsEmptyData(barsetting.grid)) {
 		barsetting.grid={borderWidth: 0,y:'10%',y2:'10%',x:'10%',x2:'10%'};
 	}
 	if (IsEmptyData(barsetting.name)) {
 		barsetting.name = 'name';
 	}
 	if (IsEmptyData(barsetting.value)) {
 		barsetting.value = 'value';
 	}
 	if (IsEmptyData(barsetting.theme)) {
 		barsetting.theme = 'macarons';
 	}
 	
 	if (IsEmptyData(barsetting.labelformatter)) {
 		barsetting.labelformatter = '{b}\n{c}';
 	}
 	
 	if (IsEmptyData(barsetting.labelposition)) {
 		barsetting.labelposition = 'top';
 	}
 	if (IsEmptyData(barsetting.tipformatter)) {
 		barsetting.tipformatter = '{b}:{c}';
 	}
 	//设置条图竖着还是横着
 	if (IsEmptyData(barsetting.overturn)) {
 		barsetting.overturn = false;
 	}
 	
 	if (IsEmptyData(barsetting.legendname)) {
 		barsetting.legendname = 'legendname';
 	}
 	if (IsEmptyData(barsetting.xdata)) {
 		barsetting.xdata = 'xdata';
 	}
 	if (IsEmptyData(barsetting.ydata)) {
 		barsetting.ydata = 'ydata';
 	}
 	
 	//是否显示类目的label
 	if (IsEmptyData(barsetting.isItemLabel)) {
 		barsetting.isItemLabel = true;
 	}
 	if (IsEmptyData(barsetting.itemPosition)) {
 		barsetting.itemPosition = 'top';
 	}
 	if (IsEmptyData(barsetting.itemFormatter)) {
 		barsetting.itemFormatter = '{b}\n{c}';
 	}
 	if (IsEmptyData(barsetting.yLabelfromatter)) {
 		barsetting.yLabelfromatter = '{value}';
 	}
 	
 	if (IsEmptyData(barsetting.xLabelName)) {
 		barsetting.xLabelName = '';
 	}
 	
 	var legend = "";
 	var legenddata = ajaxdata[barsetting.legendname];
 	if (barsetting.islegend) {

 		legend = {
 			orient : barsetting.orienttype,
 			x : barsetting.legendxalign,
 			y :	barsetting.legendyalign,
 			data : legenddata
 		};
 	}

 	var labelstyle = {
 		rotate : 0
 	};

 	if (barsetting.islongtext) {
 		labelstyle = {
 			rotate : -45,
 			textStyle : {
 				align : 'left',
 				baseline : 'middle',
 				fontSize : 12
 			}
 		};
 	}
 	//x轴和y轴数据
 	var xdata = ajaxdata[barsetting.xdata];
 	
 	var xtype = 'category';
 	var ytype = 'value';
 	
 	if(barsetting.overturn){
 		//横纵坐标轴反向
 		xtype = 'value';
 		ytype = 'category';
 		//将labe右侧显示
 		barsetting.labelposition = 'right';
 	}
 	//itemStyle
 	var itemStyle = {normal:{label:{show:barsetting.isItemLabel,position:barsetting.itemPosition,formatter:barsetting.itemFormatter}}}
 	var bardata = [];
 	for(var i=0;i<legenddata.length;i++){
 		var barItem = {};
 		//系列名
 		barItem.name = legenddata[i];
 		//类型为bar
 		barItem.type = "bar";
 		//数据
 		barItem.data = ajaxdata[barsetting.ydata][i];
 		//最大宽度40
 		barItem.barMaxWidth = 40;
 		//条图的样式
 		barItem.itemStyle = itemStyle;
 		bardata.push(barItem);
 	}
 	var option = {
 		title : {
 			text : barsetting.titletext,
 			subtext : barsetting.subtitletext,
 			x : barsetting.titlealign
 		},
 		tooltip : {
 			show : barsetting.istooltip,
 			trigger : 'item',
 			formatter : barsetting.tipformatter,
 		},
 		
 		toolbox : {
 			show : barsetting.istoolbox,
 			feature : {
 				mark : {
 					show : false
 				},
 				dataView : {
 					show : true,
 					readOnly : false
 				},
 				magicType : {
 					show : false,
 					type : [ 'bar', 'line', 'stack', 'tiled' ]
 				},
 				restore : {
 					show : true
 				},
 				saveAsImage : {
 					show : true
 				}
 			}
 		},
 		calculable : false,
 		legend : legend,
 		xAxis : [{
 			// width: '50%',
 			type : xtype,
 			data : xdata,
 			name:barsetting.xLabelName,
 			show:true,
 			axisLabel : labelstyle
 		}],
 		yAxis : [{
 				    type: ytype,
 				    data: xdata,
 				    show:true,
 				    axisLabel:{
				    	formatter:barsetting.yLabelfromatter
				    }
 				    
 				}],
 		grid : barsetting.grid,
 		series : bardata
 	};


 	var myChart1 = null;
 	require([ 'echarts', 'echarts/chart/bar', 'echarts/chart/line' ], function(
 			ec) {
 		var ecConfig = require('echarts/config');
 		//
 		$('#'+divid).attr('_echarts_instance_','');
 		myChart1 = ec.init(document.getElementById(divid),barsetting.theme);
 		
 		myChart1.clear();
 		
 		myChart1.setOption(option);
 		
 		//点击事件
 		
 		if(!IsEmptyData(barsetting.clickFunc)){
 			 //为echarts添加点击事件
 			myChart1.on(ecConfig.EVENT.CLICK,function(param){
 			
 	        	//判断是否需要从外界传点击参数
 	        	if(IsEmptyData(barsetting.clickParams)){
 	        		//没有额外的参数直接传echart参数
 	        		barsetting.clickFunc(param);
 	        	}else{
 	        		//setting里面有额外的参数，传两个
 	        		barsetting.clickFunc(param,barsetting.clickParams);
 	        	}
 	        	
 	        })
 		}
 		window.onresize = myChart1.resize;
 	});
 	
 	// var ecConfig = require('echarts/config');
 	return myChart1;
 }
  
  
  
  
  /**
   * 柱线混合图构建辅助方法
   * 
   * @param divid
   *            容器ID
   * @param ajaxdata
   *            JSON数据
   * @param barsetting
   *            包含:name, valuearry, textarry, typearry, yAxisarry, titletext,
   *            subtitletext, islegend, legendalign, istoolbox, titlealign,
   *            orienttype
   * @param name
   *            名称 列名
   * @param valuearry
   *            值 列名数组
   * @param textarry
   *            图例 名称数组
   * @param typearry
   *            显示类型 数组 柱bar 线line
   * @param stackarry
   *            群组属性（相同群组名称的多柱显示为层叠效果）
   * @param yAxisarry
   *            y轴显示名称和单位集合 例:[{ name : '数量', text : '个' }, { name : '概率', text :
   *            '%' } ];
   * @param titletext
   *            主标题
   * @param subtitletext
   *            副标题
   * @param islegend
   *            是否显示图例，默认值true
   * @param legendalign
   *            图例显示位置，默认值left
   * @param istoolbox
   *            是否显示右上方的工具栏，默认值true
   * @param istooltip
   *            是否显示提示框，默认值true
   * @param titlealign
   *            标题位置，默认值center
   * @param orienttype
   *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
   * @param islongtext
   *            长文本处理方式，倾斜45°，12px
   * @param chartwidth
   *            统计图主体的宽度，默认70%
   * @param chartheight
   *            统计图主体的高度，默认70%
   * @param isdataZoom
   *            是否显示时间轴
   * @param zoomstart
   *            时间轴区间开始百分比（区间在0-100）
   * @param zoomend
   *            时间轴区间结束百分比（区间在0-100）
   * @param isrealtime
   *            缩放变化是否实时显示，默认true
   * @param zoomheight
   *            时间轴区域的高度
   * @param x
   *            主体的x坐标
   * @param y
   *            主体的y坐标
   */
 function InitECharts_mixBarLine(divid, ajaxdata, settings) {
  	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
  		alert("绑定的容器ID不存在");
  		return false;
  	}

  	if (IsEmptyData(ajaxdata)) {
  		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
  			document.getElementById(divid).removeChild(
  					document.getElementById(divid).childNodes[i]);
  		}
  	}

  	if (IsEmptyData(settings)) {
  		alert("设置为空或不正确");
  		return false;
  	}

  	if (IsEmptyData(settings.islegend)) {
  		//柱形图不显示图例
  		settings.islegend = true;
  	}

  	if (IsEmptyData(settings.legendxalign)) {
  		settings.legendxalign = 'left';
  	}
  	if (IsEmptyData(settings.legendyalign)) {
  		settings.legendyalign = 'bottom';
  	}

  	if (IsEmptyData(settings.istoolbox)) {
  		settings.istoolbox = true;
  	}

  	if (IsEmptyData(settings.istooltip)) {
  		settings.istooltip = true;
  	}

  	if (IsEmptyData(settings.titlealign)) {
  		settings.titlealign = "center";
  	}
  	if (IsEmptyData(settings.orienttype)) {
  		settings.orienttype = "horizontal";
  	}


  	if (IsEmptyData(settings.islongtext)) {
  		settings.islongtext = false;
  	}
  	
  	if (IsEmptyData(settings.grid)) {
  		settings.grid={borderWidth: 0,y:'10%',y2:'10%',x:'10%',x2:'10%'};
  	}
  	if (IsEmptyData(settings.name)) {
  		settings.name = 'name';
  	}
  	if (IsEmptyData(settings.value)) {
  		settings.value = 'value';
  	}
  	if (IsEmptyData(settings.theme)) {
  		settings.theme = 'macarons';
  	}
  	
  	if (IsEmptyData(settings.labelformatter)) {
  		settings.labelformatter = '{b}\n{c}';
  	}
  	
  	if (IsEmptyData(settings.labelposition)) {
  		settings.labelposition = 'top';
  	}
  	if (IsEmptyData(settings.tipformatter)) {
  		settings.tipformatter = '{b}:{c}';
  	}
  	//设置条图竖着还是横着
  	if (IsEmptyData(settings.overturn)) {
  		settings.overturn = false;
  	}
  	
  	if (IsEmptyData(settings.legendname)) {
  		settings.legendname = 'legendname';
  	}
  	if (IsEmptyData(settings.xdata)) {
  		settings.xdata = 'xdata';
  	}
  	if (IsEmptyData(settings.ydata)) {
  		settings.ydata = 'ydata';
  	}
  	
  	//是否显示类目的label
  	if (IsEmptyData(settings.isItemLabel)) {
  		settings.isItemLabel = true;
  	}
  	if (IsEmptyData(settings.itemPosition)) {
  		settings.itemPosition = 'top';
  	}
  	if (IsEmptyData(settings.itemFormatter)) {
  		settings.itemFormatter = '{b}\n{c}';
  	}
  	if (IsEmptyData(settings.yLabelfromatter)) {
  		settings.yLabelfromatter = '{value}';
  	}
  	
  	if (IsEmptyData(settings.xLabelName)) {
  		settings.xLabelName = '';
  	}
  	
  	if (IsEmptyData(settings.yLabelName)) {
  		settings.yLabelName = '';
  	}
  	
  	var legend = "";
  	var legenddata = ajaxdata[settings.legendname];
  	if (settings.islegend) {

  		legend = {
  			orient : settings.orienttype,
  			x : settings.legendxalign,
  			y :	settings.legendyalign,
  			data : legenddata
  		};
  	}

  	var labelstyle = {
  		rotate : 0
  	};

  	if (settings.islongtext) {
  		labelstyle = {
  			rotate : -45,
  			textStyle : {
  				align : 'left',
  				baseline : 'middle',
  				fontSize : 12
  			}
  		};
  	}
  	//x轴和y轴数据
  	var xdata = ajaxdata[settings.xdata];
  	
  	var xtype = 'category';
  	var ytype = 'value';
  	
  	if(settings.overturn){
  		//横纵坐标轴反向
  		xtype = 'value';
  		ytype = 'category';
  		//将labe右侧显示
  		settings.labelposition = 'right';
  	}
  	//itemStyle
  	//var itemStyle = {normal:{label:{show:settings.isItemLabel,position:settings.itemPosition,formatter:settings.itemFormatter}}}
  	var bardata = [];
  	for(var i=0;i<legenddata.length;i++){
  		var barItem = {};
  		//系列名
  		barItem.name = legenddata[i];
  		if(barItem.name=='零售率'){
  			barItem.type = "line";
  			barItem.yAxisIndex = 1;
  		}else{
  			barItem.barMaxWidth = 40;
  			barItem.type = 'bar';
  		}
  		//类型为bar
  		
  		
  		//数据
  		barItem.data = ajaxdata[settings.ydata][i];
  		//最大宽度40
  		//barItem.barMaxWidth = 40;
  		//条图的样式
  		//barItem.itemStyle = itemStyle;
  		bardata.push(barItem);
  	}
  	var option = {
  		title : {
  			text : settings.titletext,
  			subtext : settings.subtitletext,
  			x : settings.titlealign
  		},
  		tooltip : {
  			show : settings.istooltip,
  			trigger : 'item',
  			formatter : settings.tipformatter,
  		},
  		
  		toolbox : {
  			show : settings.istoolbox,
  			feature : {
  				mark : {
  					show : false
  				},
  				dataView : {
  					show : true,
  					readOnly : false
  				},
  				magicType : {
  					show : false,
  					type : [ 'bar', 'line', 'stack', 'tiled' ]
  				},
  				restore : {
  					show : true
  				},
  				saveAsImage : {
  					show : true
  				}
  			}
  		},
  		calculable : false,
  		legend : legend,
  		xAxis : [{
  			// width: '50%',
  			type : xtype,
  			data : xdata,
  			name:settings.xLabelName,
  			show:true,
  			axisLabel : labelstyle
  		}],
  		yAxis : [{
  				    type: ytype,
  				    show:true,
  				    name:'单位：台',
  				    /*axisLabel:{
 				    	formatter:settings.yLabelfromatter
 				    }*/
  				    
  				},
  				{
  				    type: ytype,
  				    show:true,
  				    name:'零售率',
  				    axisLabel:{
 				    	formatter:settings.yLabelfromatter
 				    }
  				    
  				}
  		
  		
  			],
  		grid : settings.grid,
  		series : bardata
  	};


  	var myChart1 = null;
  	require([ 'echarts', 'echarts/chart/bar', 'echarts/chart/line' ], function(
  			ec) {
  		var ecConfig = require('echarts/config');
  		//
  		$('#'+divid).attr('_echarts_instance_','');
  		myChart1 = ec.init(document.getElementById(divid),settings.theme);
  		
  		myChart1.clear();
  		
  		myChart1.setOption(option);
  		
  		//点击事件
  		
  		if(!IsEmptyData(settings.clickFunc)){
  			 //为echarts添加点击事件
  			myChart1.on(ecConfig.EVENT.CLICK,function(param){
  			
  	        	//判断是否需要从外界传点击参数
  	        	if(IsEmptyData(settings.clickParams)){
  	        		//没有额外的参数直接传echart参数
  	        		settings.clickFunc(param);
  	        	}else{
  	        		//setting里面有额外的参数，传两个
  	        		settings.clickFunc(param,settings.clickParams);
  	        	}
  	        	
  	        })
  		}
  		window.onresize = myChart1.resize;
  	});
  	
  	// var ecConfig = require('echarts/config');
  	return myChart1;
  }
 
 
 /**
  * 柱线混合图构建辅助方法
  * 
  * @param divid
  *            容器ID
  * @param ajaxdata
  *            JSON数据
  * @param barsetting
  *            包含:name, valuearry, textarry, typearry, yAxisarry, titletext,
  *            subtitletext, islegend, legendalign, istoolbox, titlealign,
  *            orienttype
  * @param name
  *            名称 列名
  * @param valuearry
  *            值 列名数组
  * @param textarry
  *            图例 名称数组
  * @param typearry
  *            显示类型 数组 柱bar 线line
  * @param stackarry
  *            群组属性（相同群组名称的多柱显示为层叠效果）
  * @param yAxisarry
  *            y轴显示名称和单位集合 例:[{ name : '数量', text : '个' }, { name : '概率', text :
  *            '%' } ];
  * @param titletext
  *            主标题
  * @param subtitletext
  *            副标题
  * @param islegend
  *            是否显示图例，默认值true
  * @param legendalign
  *            图例显示位置，默认值left
  * @param istoolbox
  *            是否显示右上方的工具栏，默认值true
  * @param istooltip
  *            是否显示提示框，默认值true
  * @param titlealign
  *            标题位置，默认值center
  * @param orienttype
  *            图例的排序方式，默认为垂直显示(vertical),水平显示属性为horizontal
  * @param islongtext
  *            长文本处理方式，倾斜45°，12px
  * @param chartwidth
  *            统计图主体的宽度，默认70%
  * @param chartheight
  *            统计图主体的高度，默认70%
  * @param isdataZoom
  *            是否显示时间轴
  * @param zoomstart
  *            时间轴区间开始百分比（区间在0-100）
  * @param zoomend
  *            时间轴区间结束百分比（区间在0-100）
  * @param isrealtime
  *            缩放变化是否实时显示，默认true
  * @param zoomheight
  *            时间轴区域的高度
  * @param x
  *            主体的x坐标
  * @param y
  *            主体的y坐标
  */
  function InitECharts_line(divid, ajaxdata, chartsetting) {
 	if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
 		alert("绑定的容器ID不存在");
 		return false;
 	}

 	if (IsEmptyData(ajaxdata)) {
 		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
 			document.getElementById(divid).removeChild(
 					document.getElementById(divid).childNodes[i]);
 		}
 	}

 	if (IsEmptyData(chartsetting)) {
 		alert("设置为空或不正确");
 		return false;
 	}
 	//是否显示图例
 	if (IsEmptyData(chartsetting.islegend)) {
 		//折毛线图不显示图例
 		chartsetting.islegend = true;
 	}
 	//图例位置
 	if (IsEmptyData(chartsetting.legendxalign)) {
 		chartsetting.legendxalign = 'left';
 	}
 	//图例位置
 	if (IsEmptyData(chartsetting.legendyalign)) {
 		chartsetting.legendyalign = 'bottom';
 	}
 	//显示提示框
 	if (IsEmptyData(chartsetting.istoolbox)) {
 		chartsetting.istoolbox = true;
 	}
	//显示提示框
 	if (IsEmptyData(chartsetting.istooltip)) {
 		chartsetting.istooltip = true;
 	}
 	//标题位置
 	if (IsEmptyData(chartsetting.titlealign)) {
 		chartsetting.titlealign = "center";
 	}
 	//
 	if (IsEmptyData(chartsetting.orienttype)) {
 		chartsetting.orienttype = "horizontal";
 	}


 	if (IsEmptyData(chartsetting.islongtext)) {
 		chartsetting.islongtext = false;
 	}
 	
 	if (IsEmptyData(chartsetting.grid)) {
 		chartsetting.grid={borderWidth: 0,y:'10%',y2:'15%',x:'10%',x2:'10%'};
 	}
 	//数据json 键值对key
 	if (IsEmptyData(chartsetting.name)) {
 		chartsetting.name = 'name';
 	}
 	if (IsEmptyData(chartsetting.value)) {
 		chartsetting.value = 'value';
 	}
 	
 	if (IsEmptyData(chartsetting.theme)) {
 		chartsetting.theme = 'macarons';
 	}
 	
 	if (IsEmptyData(chartsetting.labelformatter)) {
 		chartsetting.labelformatter = '{b}\n{c}';
 	}
 	
 	if (IsEmptyData(chartsetting.labelposition)) {
 		chartsetting.labelposition = 'top';
 	}
 	if (IsEmptyData(chartsetting.tipformatter)) {
 		chartsetting.tipformatter = '{b}:{c}';
 	}
 	
 	if (IsEmptyData(chartsetting.legendname)) {
 		chartsetting.legendname = 'legendname';
 	}
 	if (IsEmptyData(chartsetting.xdata)) {
 		chartsetting.xdata = 'xdata';
 	}
 	if (IsEmptyData(chartsetting.ydata)) {
 		chartsetting.ydata = 'ydata';
 	}
 	
 	if (IsEmptyData(chartsetting.yLabelfromatter)) {
 		chartsetting.yLabelfromatter = '{value}';
 	}
	if (IsEmptyData(chartsetting.yLabelName)) {
 		chartsetting.yLabelName = '';
 	}
 	
 	
 	var legend = "";
 	//图例数据
 	var legenddata = ajaxdata[chartsetting.legendname];
 	
 	//图例选中状态
 	if (IsEmptyData(chartsetting.selectedNum)) {
 		//默认全选中位图例
 		chartsetting.selectedNum = legenddata.length;
 	}
 	if (chartsetting.islegend) {
 		//设置不选中的状态
 		var noSelected = {};
 		/*for(var i=legenddata.length-1;i>=(legenddata.length-chartsetting.noSelectedNum);i--){
 			var name = legenddata[i];
 			noSelected[name] = false;
 		}*/
 		for(var i = chartsetting.selectedNum; i<legenddata.length; i++){
 			var name = legenddata[i];
 			noSelected[name] = false;
 		}
 		legend = {
 			orient : chartsetting.orienttype,
 			x : chartsetting.legendxalign,
 			y : chartsetting.legendyalign,
 			selected:noSelected,
 			data : legenddata
 		};
 	}

 	var labelstyle = {
 		rotate : 0
 	};

 	if (chartsetting.islongtext) {
 		labelstyle = {
 			rotate : -45,
 			textStyle : {
 				align : 'left',
 				baseline : 'middle',
 				fontSize : 12
 			}
 		};
 	}
 	//x轴和y轴数据
 	var xdata = ajaxdata[chartsetting.xdata];
 	
 	var ydata = ajaxdata[chartsetting.ydata];
 	//x周为类目
 	var xtype = 'category';
 	//y轴为值
 	var ytype = 'value';
 	
 	//折线数组
 	var lineData = [];
 	for(var i=0;i<legenddata.length;i++){
 		//声明line的对象封装line
 		var lineItem = {};
 		//折线图折线的name
 		lineItem.name = legenddata[i];
 		//折线图类型
 		lineItem.type = 'line';
 		
 		//折线图数据
 		lineItem.data = ydata[i];
 		//折线图放数据
 		lineData.push(lineItem);
 	}
 	
 	
 	var option = {
 		title : {
 			text : chartsetting.titletext,
 			subtext : chartsetting.subtitletext,
 			x : chartsetting.titlealign
 		},
 		tooltip : {
 			show : chartsetting.istooltip,
 			trigger : 'item',
 			formatter : chartsetting.tipformatter,
 		},
 		
 		toolbox : {
 			show : chartsetting.istoolbox,
 			feature : {
 				mark : {
 					show : false
 				},
 				dataView : {
 					show : true,
 					readOnly : false
 				},
 				magicType : {
 					show : false,
 					type : [ 'bar', 'line', 'stack', 'tiled' ]
 				},
 				restore : {
 					show : true
 				},
 				saveAsImage : {
 					show : true
 				}
 			}
 		},
 		calculable : false,
 		legend : legend,
 		xAxis : [{
 			// width: '50%',
 			type : xtype,
 			data : xdata,
 			show:true,
 			axisLabel : labelstyle,
 			boundaryGap:false
 		}],
 		yAxis : [{
 				    type: ytype,
 				    show:true,
 				    name:chartsetting.yLabelName,
 				    axisLabel:{
 				    	formatter:chartsetting.yLabelfromatter
 				    }
 				}],
 		grid : chartsetting.grid,
 		series : lineData
 	};


 	var myChart1 = null;
 	require([ 'echarts', 'echarts/chart/bar', 'echarts/chart/line' ], function(
 			ec) {
 		var ecConfig = require('echarts/config');
 		myChart1 = ec.init(document.getElementById(divid),chartsetting.theme);
 		myChart1.clear();
 		myChart1.setOption(option);
 	
 		//点击事件
 		if(!IsEmptyData(chartsetting.clickFunc)){
 			 //为echarts添加点击事件
 	      
 			myChart1.on(ecConfig.EVENT.CLICK,function(param){
 	        	//判断是否需要从外界传点击参数
 	        	if(IsEmptyData(chartsetting.clickParams)){
 	        		//没有额外的参数直接传echart参数
 	        		chartsetting.clickFunc(param);
 	        	}else{
 	        		//setting里面有额外的参数，传两个
 	        		chartsetting.clickFunc(param,chartsetting.clickParams);
 	        	}
 	        	
 	        })
 		}
 		window.onresize = myChart1.resize;
 	});
 	
 	// var ecConfig = require('echarts/config');
 	return myChart1;
 }

 /**
  * 没有数据时
  * @param divid
  * @returns
  */
 function showNoDataCharts(divid){
	 	 var option = { 
	 			 		xAxis : [
	    		             {
	    		                 type : 'value'
	    		             }
	    		         ],
	    		         yAxis : [
	    		             {
	    		                 type : 'category',
	    		                 data : []
	    		             }
	    		         ],
    		       noDataLoadingOption:{
    		     	   	    	text:'没有符合条件的数据！',
    		     	 	    	effect:'bubble',
    		     	 	    	effectOption : {
	    		     	 	    	effect: {
	    		     	 	    		n: 0
	    		     	 	    	}
    		     	 	    	},
    		     	 	    	textStyle: {
	    		     	 	    	fontSize: 18,
	    		     	 	    	fontFamily: 'Microsoft YaHei,微软雅黑'
    		     	 	    	}
    		     	 	    },
    		         series : [
    		             {
    		               
    		                 type:'bar',
    		                 itemStyle : { normal: {label : {show: false, position: 'insideRight'}}},
    		                 data:[]
    		             }
    		            
    		         ]
    		     };
	 	var myChart1 = null;
		require([ 'echarts', 'echarts/chart/bar' ], function(
				ec) {
			myChart1 = ec.init(document.getElementById(divid),'macarons');
			myChart1.clear();
			myChart1.setOption(option);
			window.onresize = myChart1.resize;
		});
		
		return myChart1;
		
	}
 
 /**
  * 
  * @param tabId
  */
 function setSampleNum(tabId){
	 $("#"+tabId).next().text('0/0');
 }
 
 /**
  * 词云图封装的方法
  * @param ajaxData json数据
  * @param divid domid
  */
 function InitECharts_WordCloud(ajaxData,divid){
	 
	 var seriesData= [];
	 
	if(ajaxData.data != null && ajaxData.data != ''){
		
		var dataTemp = ajaxData.data;
		 $.each(dataTemp,function(i,item){
				var valueNum = item.VALUE*300;
				seriesData.push({name:item.NAME,value:valueNum,itemStyle:createRandomItemStyle()});
		}); 
		 var seriesArr = [{  
	         type: 'wordCloud', 
	         size: ['90%', '90%'],
	         textRotation : [0, 45, 90, -45],
	         textPadding: 0,
	         itemStyle:{
	        	 normal:{
	        		 textStyle:{
	        			 fontFamily:'Microsoft YaHei,微软雅黑',
	        			 fontStyle:'normal',
	        			 fontWeight:'normal'
	        		 }
	         }},
	         autoSize: {enable: true,  minSize: 14},
	         data:seriesData}];
		//渲染图表
		showWordCloud(seriesArr,divid);
	}else{
		showNoDataCharts(divid);
	}
	
	function showWordCloud(seriesArr,divid){
		 var option = {
					title: {
				        x: 'item',
				        textStyle:{
				        	fontFamily: 'Microsoft YaHei,微软雅黑,宋体',
				        	fontSize:18,
				        	fontWeight:'normal',
				        	color:'#6C6C6C'
				        }
				    },
				    tooltip: {
				    	show: true,
				    	formatter:"{b} :{c}",
				        textStyle:{
				        	fontFamily: 'Microsoft YaHei,微软雅黑,宋体',
				        	fontWeight:'normal',
				        }
				    },
				  
				  noDataLoadingOption:{
					text:'没有符合条件的数据！',
				  	effect:'bubble',
				  	effectOption : {
					  	effect: {
					  	n: 0
					  	}
				  	},
				  	textStyle: {
					  	fontSize: 18,
					  	fontFamily: 'Microsoft YaHei,微软雅黑',
					  	fontWeight:'normal',
					 	color:'#6C6C6C'
				  		}
				  	},
				    loadingOption:{
				    	text:'正在加载中...',
				    	effect:'bar'
				    },
				    toolbox: {
				        show: true,
				        feature: {
				        	dataView : {
								show : true,
								readOnly : false
							},
				            restore: {show: true},
				            saveAsImage: {show: true}
				        }
				    },
				    tooltip:{
				    	show:false
				    },
				    series: seriesArr
			};
			
		 var myChart = null;
		 require([ 'echarts', 'echarts/chart/wordCloud' ], 
		 		function(ec) {
			 		var ecConfig = require('echarts/config');
			 		myChart = ec.init(document.getElementById(divid));
			 		myChart.setOption(option);
		 		}
		 );
	}
}

 /**
  * 仪表盘初始化函数
  * @param divid
  * @param ajaxdata
  * @param chartsetting
  */
 function InitECharts_dashboard(divid, ajaxdata, chartsetting){
	 
	 if (IsEmptyData(divid) || IsEmptyData(document.getElementById(divid))) {
	 		alert("绑定的容器ID不存在");
	 		return false;
	 	}

	 	if (IsEmptyData(ajaxdata)) {
	 		for ( var i = 0; i < document.getElementById(divid).childNodes.length; i++) {
	 			document.getElementById(divid).removeChild(
	 					document.getElementById(divid).childNodes[i]);
	 		}
	 	}

	 	if (IsEmptyData(chartsetting)) {
	 		alert("设置为空或不正确");
	 		return false;
	 	}
	 
	 
	 	//显示提示框
	 	if (IsEmptyData(chartsetting.istoolbox)) {
	 		chartsetting.istoolbox = true;
	 	}
		//显示提示框
	 	if (IsEmptyData(chartsetting.istooltip)) {
	 		chartsetting.istooltip = true;
	 	}
	 	//标题位置
	 	if (IsEmptyData(chartsetting.titlealign)) {
	 		chartsetting.titlealign = "center";
	 	}
	 	//
	 	
	 	//数据json 键值对key
	 	if (IsEmptyData(chartsetting.name)) {
	 		chartsetting.name = 'name';
	 	}
	 	if (IsEmptyData(chartsetting.value)) {
	 		chartsetting.value = 'value';
	 	}
	 	
	 	if (IsEmptyData(chartsetting.theme)) {
	 		chartsetting.theme = 'macarons';
	 	}
	 	
	 	if (IsEmptyData(chartsetting.tipformatter)) {
	 		chartsetting.tipformatter = '{b}:{c}';
	 	}
	 	
	 	
	 	
	 	
	 var option = {
		 title : {
	 			text : chartsetting.titletext,
	 			subtext : chartsetting.subtitletext,
	 			x : chartsetting.titlealign
	 		},
	 		tooltip : {
	 			show : chartsetting.istooltip,
	 			trigger : 'item',
	 			formatter : chartsetting.tipformatter,
	 		},
	 		
	 		toolbox : {
	 			show : chartsetting.istoolbox,
	 			feature : {
	 				mark : {
	 					show : false
	 				},
	 				dataView : {
	 					show : true,
	 					readOnly : false
	 				},
	 				magicType : {
	 					show : false,
	 					type : [ 'bar', 'line', 'stack', 'tiled' ]
	 				},
	 				restore : {
	 					show : true
	 				},
	 				saveAsImage : {
	 					show : true
	 				}
	 			}
	 		},
	 		series : [
		 		         {
		 		             name:'业务指标',
		 		             type:'gauge',
		 		             min:0,
		 		             max:1,
		 		             detail : {formatter:'{value}'},
		 		             data:ajaxdata
		 		         }
	 		         ]	 
	 };
	 
	 var myChart1 = null;
	 	require([ 'echarts', 'echarts/chart/gauge' ], function(
	 			ec) {
	 		var ecConfig = require('echarts/config');
	 		myChart1 = ec.init(document.getElementById(divid),chartsetting.theme);
	 		myChart1.clear();
	 		myChart1.setOption(option);
	 		window.onresize = myChart1.resize;
	 	});
	 	
	 	// var ecConfig = require('echarts/config');
	 	return myChart1;
 }
/**
 * 词原图计算的方法
 */
function createRandomItemStyle() {
     return {
         normal: {
             color: 'rgb(' + [
                 Math.round(Math.random() * 160),
                 Math.round(Math.random() * 160),
                 Math.round(Math.random() * 160)
             ].join(',') + ')'
         }
     };
 }
